package com.controller.system.partner;

import com.service.system.partner.PartnerService;
import org.apache.commons.lang.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.servlet.http.HttpServletRequest;
import java.util.HashMap;
import java.util.Map;

/**
 * 合伙人管理
 * @author Alexpy
 * @date 2018-04-12
 */
@Controller()
@RequestMapping("/partner")
public class PartnerController {

    @Autowired
    PartnerService partnerService;

    /**
     * 查询合伙人列表
     *
     * @param request
     * @return
     */
    @ResponseBody
    @RequestMapping(value = "/list", method = {RequestMethod.POST, RequestMethod.GET})
    public Map<String, Object> findPartnerList(HttpServletRequest request) {
        Map<String, Object> map = new HashMap<>();
        map.put("pageSize", request.getParameter("pageSize"));
        map.put("pageNum", request.getParameter("pageNum"));

        if (StringUtils.isNotEmpty(request.getParameter("provinceCode"))) {
            map.put("provinceCode", request.getParameter("provinceCode"));
        }
        if (StringUtils.isNotEmpty(request.getParameter("cityCode"))) {
            map.put("cityCode", request.getParameter("cityCode"));
        }
        if (StringUtils.isNotEmpty(request.getParameter("countyCode"))) {
            map.put("countyCode", request.getParameter("countyCode"));
        }
        return partnerService.findPartnerList(map);
    }

    /**
     * 合伙人排行
     *
     * @param request
     * @return
     */
    @ResponseBody
    @RequestMapping(value = "/order", method = {RequestMethod.POST, RequestMethod.GET})
    public Map<String, Object> partnerOrder(HttpServletRequest request) {
        Map<String, Object> map = new HashMap<>();
        map.put("pageSize", request.getParameter("pageSize"));
        map.put("pageNum", request.getParameter("pageNum"));
        //排行条件
        map.put("flag", request.getParameter("flag"));
        return partnerService.partnerOrder(map);
    }

    /**
     * 查询合伙人列表
     * @param request
     * @return
     */
    @RequestMapping(value = "/findInviterUserList",method = {RequestMethod.POST,RequestMethod.GET})
    @ResponseBody
    public Map<String,Object> findInviterUserList(HttpServletRequest request){
        int pageSize = 10;
        int pageNum = 1;
        if(StringUtils.isNotEmpty(request.getParameter("pageSize"))){
            pageSize = Integer.parseInt(request.getParameter("pageSize"));
        }
        if(StringUtils.isNotEmpty(request.getParameter("pageNum"))){
            pageNum = Integer.parseInt(request.getParameter("pageNum"));
        }
        String userId = request.getParameter("userId"); //邀请者用户id

        return partnerService.findInviterUserList(userId,pageSize,pageNum);
    }
}
